const app = getApp();
const Controller = require('../../controllers/controllers.js').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTixi:"none",
    bottomLift:0,
    msgData:{},
    msgData2:{},
    page:1,
    contact:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {bottomLift} = app.globalData
    if(bottomLift>=0){
      app.getDeviceSize().then(res => {
        const {bottomLift} = res
        this.setData({
          bottomLift
        })
      })
    }else{
      this.setData({
        bottomLift
      })
    }
    this.getuserRecordList(this.data.page)
    this.getUserRevenueData()

    // 提现提示
    Controller.appinfo({key:"key-withdrawal-info"}).then((res)=>{
        this.setData({
          contact:res.data.baseData.content
        })
    })

  },
  help(){
    if(this.data.isTixi=="grid"){
      this.setData({
        isTixi:"none"
      })
    }else{
      this.setData({
        isTixi:"grid"
      })
    }
    
  },
  toWithdrawal(){
    wx.navigateTo({
      url: '../../Withdrawal/Withdrawal?money='+this.data.msgData.unSettle
    })
  },
  toInvitationList(){
    wx.navigateTo({
      url: '../../InvitationList/InvitationList'
    })
  },
  toLink(e){
    // console.log(e.currentTarget.dataset)
    wx.navigateTo({
      url: '../../PaymentList/PaymentList?activityId='+e.currentTarget.dataset.activityid+'&activityTimeId='+e.currentTarget.dataset.activitytimeid
    })
  },
  getuserRecordList(page,p){  //邀请收益列表
    Controller.userRecordList({'page':page}).then((res)=>{
        
      if(p){
          var list=this.data.msgData2.list
          list.push(...res.data.baseData.list);
          
          this.setData({
            'msgData2.list':list
          })
        }else{
            this.setData({
              msgData2:res.data.baseData
            })
        }
       
          this.setData({
            page: this.data.page+1
          })
    })
  },
  getUserRevenueData(){  //获取用户收益数据和邀请总人数
     Controller.userRevenueData({}).then((res)=>{
          
          this.setData({
            msgData:res.data.baseData
          })
          // console.log(this.data.msgData)
     })
  }
  ,
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      if(this.data.page < (this.data.msgData2.totalRow /10)+1 ){
          this.getuserRecordList(this.data.page,true)
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})